import { reqCategoryList,reqGetBannerList,reqGetFloor } from '../../api/index';
const actions = {
  // 不加 async 则返回的是一个 promise 不会返回值
  // 获取三级联动的数据
  async categoryList({ commit }) {
    // 返回 promise 值
    let result = await reqCategoryList();
    // console.log(result.data);
    if (result.code === 200) {
      // 讲获取的数据 传给 mutations
      commit('CATEGORYLIST', result);
    }
  },

  // 获取 banner 轮播图的数据
  async getBannerList(context){
    // console.log('正在发送ajax');
    let result = await reqGetBannerList();
    if (result.code === 200) {
      // 讲获取的数据 传给 mutations
      context.commit('GETBANNERLIST', result.data);
    }
  },
  async getFloor({commit}){
    let floor = await reqGetFloor()
    if(floor.code === 200){
      commit('GETFLOOR',floor.data)
    }
  }
};
const mutations = {
  CATEGORYLIST(state, val) {
    state.categoryList = val;
  },
  GETBANNERLIST(start,val){
    // console.log('修改数据中')
    state.getBannerList = val
    // console.log(state); 
  },
  GETFLOOR(state,floor){
    state.getFloor = floor
  }
};
const state = {
  categoryList: [],
  getBannerList:[],
  getFloor:[]
};
const getters = {};

export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
};
